package com.itheima.job;

import java.util.Random;
import java.util.concurrent.*;

public class Test02 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        Future<Double> f1 = pool.submit(new MyThread());
        Future<Double> f2 = pool.submit(new MyThread());
        Future<Double> f3 = pool.submit(new MyThread());
        //一开始的思路
        FutureTask<Double> f4 = new FutureTask<>(new MyThread());
        pool.submit(f4);
        System.out.println(f4.get());
        //.....

        System.out.println(f1.get());
        System.out.println(f2.get());
        System.out.println(f3.get());
        pool.shutdown();
    }
}

class MyThread implements Callable<Double>{
    private Random random = new Random();
    @Override
    public Double call() throws Exception {
        double d = 0.0;
        for (int i = 0; i < 10; i++) {
            double v = random.nextInt(100)+1;
            d +=v;
        }
        return d/10.0;
    }
}
